﻿/*=================================================================
* 版权信息：Copyright (C) 2005-2011 捷点科技 All Rights Reserved.
* 文件名称：CNVP_ProPropertyDescripttion.cs
* 创建标识：曾乃强 15158756652 2011-04-14 10:04:52
* 修改标识：
* 功能描述：
===================================================================*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using CNVP.Framework.Helper;
using CNVP.Config;

namespace CNVP.JShop.DAL
{
    /// <summary>
    /// 对*CNVP_ProPropertyDescripttion*操作数据库(针对SQL Server)的实现
    /// </summary>
    public class CNVP_ProPropertyDescripttion
    {
       private string Prefix = DBConfig.Prefix;
        #region DAL
        /// <summary>
        /// 添加
        /// </summary>
        public int Insert(Model.CNVP_ProPropertyDescripttion obj)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("insert into  " + Prefix + "ProPropertyDescripttion ([ProductID],[StandardValue],[ProTypeRefDescripttionID],[ProductTypeID])");
            sql.Append("values(@ProductID,@StandardValue,@ProTypeRefDescripttionID,@ProductTypeID)");
            sql.Append(";SELECT @@IDENTITY");
            SqlParameter[] pra = {
                            new SqlParameter("@ProductID",obj.ProductID),
							new SqlParameter("@StandardValue",obj.StandardValue),
							new SqlParameter("@ProTypeRefDescripttionID",obj.ProTypeRefDescripttionID),
                            new SqlParameter("@ProductTypeID",obj.ProductTypeID)
                                 };
            return Convert.ToInt32(DbHelper.ExecuteScalar(sql.ToString(), pra));
        }
        /// <summary>
        /// 修改
        /// </summary>
        public int Update(Model.CNVP_ProPropertyDescripttion obj)
        {
             StringBuilder sql = new StringBuilder();
             sql.Append("update " + Prefix + "ProPropertyDescripttion set [ProductID] = @ProductID,[StandardValue] = @StandardValue,[ProTypeRefDescripttionID] = @ProTypeRefDescripttionID,[ProductTypeID]=@ProductTypeID where [ID]=@ID ");

            SqlParameter[] pra = { 
                                     new SqlParameter("@ID",obj.ID),
							new SqlParameter("@ProductID",obj.ProductID),
							new SqlParameter("@StandardValue",obj.StandardValue),
							new SqlParameter("@ProTypeRefDescripttionID",obj.ProTypeRefDescripttionID),
                            new SqlParameter("@ProductTypeID",obj.ProductTypeID)
                                };
             return DbHelper.ExecuteNonQuery(sql.ToString(),pra);
        }
        /// <summary>
        /// 删除
        /// </summary>
        public int Delete(Model.CNVP_ProPropertyDescripttion obj)
        {
           StringBuilder sql = new StringBuilder();
           sql.Append("delete from " + Prefix + "ProPropertyDescripttion where [ID] = @ID");
           SqlParameter[] pra = {
                                new SqlParameter("@ID",obj.ID)
						
                                };
           return DbHelper.ExecuteNonQuery(sql.ToString(),pra);
        }
        /// <summary>
        /// 查看单个
        /// </summary>
        public Model.CNVP_ProPropertyDescripttion LoadById(int ID)
        {
            
            StringBuilder sql = new StringBuilder();
            sql.Append("select [ProductID],[StandardValue],[ProTypeRefDescripttionID] from " + Prefix + "ProPropertyDescripttion");
            sql.Append(" where [ID] = @ID");
            SqlParameter[] pra = {
                                 new SqlParameter("@ID",ID)
						
                                    };
            DataTable DT = DbHelper.ExecuteTable(sql.ToString(),pra);
            Model.CNVP_ProPropertyDescripttion cnvp_propropertydescripttion = new Model.CNVP_ProPropertyDescripttion();
            if (DT != null && DT.Rows.Count > 0)
            {
                DataRow dr = DT.Rows[0];
                cnvp_propropertydescripttion.ProductID = dr["ProductID"] is DBNull ? 0 : (int)dr["ProductID"];
                cnvp_propropertydescripttion.StandardValue = dr["StandardValue"] is DBNull ? String.Empty : (string)dr["StandardValue"];
                cnvp_propropertydescripttion.ProTypeRefDescripttionID = dr["ProTypeRefDescripttionID"] is DBNull ? 0 : (int)dr["ProTypeRefDescripttionID"];
            }
             return cnvp_propropertydescripttion;
        }
        #endregion

        /// <summary>
        /// 查看单个
        /// </summary>
        public Model.CNVP_ProPropertyDescripttion LoadByProTypeRefDescripttionIDAndProductID(int ProTypeRefDescripttionID,int ProductID)
        {

            StringBuilder sql = new StringBuilder();
            sql.Append("select [ID],[StandardValue] from " + Prefix + "ProPropertyDescripttion");
            sql.Append(" where [ProTypeRefDescripttionID] = @ProTypeRefDescripttionID AND [ProductID]=@ProductID");
            SqlParameter[] pra = {
                                 new SqlParameter("@ProTypeRefDescripttionID",ProTypeRefDescripttionID),
                                 new SqlParameter("@ProductID",ProductID)
						
                                    };
            DataTable DT = DbHelper.ExecuteTable(sql.ToString(), pra);
            Model.CNVP_ProPropertyDescripttion cnvp_propropertydescripttion = new Model.CNVP_ProPropertyDescripttion();
            if (DT != null && DT.Rows.Count > 0)
            {
                DataRow dr = DT.Rows[0];
                cnvp_propropertydescripttion.ID = dr["ID"] is DBNull ? 0 : (int)dr["ID"];
                cnvp_propropertydescripttion.StandardValue = dr["StandardValue"] is DBNull ? String.Empty : (string)dr["StandardValue"];
            }
            return cnvp_propropertydescripttion;
        }

        /// <summary>
        /// 查看全部,ProductID
        /// </summary>
        public List<Model.CNVP_ProPropertyDescripttion> LoadAll(int ProductID)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select [ID],[StandardValue],[ProTypeRefDescripttionID] from " + Prefix + "ProPropertyDescripttion");
            sql.Append(" where [ProductID] = @ProductID");
            SqlParameter[] pra = {
                                 new SqlParameter("@ProductID",ProductID)
						
                                    };
            DataTable DT = DbHelper.ExecuteTable(sql.ToString(),pra);
            List<Model.CNVP_ProPropertyDescripttion> list = new List<Model.CNVP_ProPropertyDescripttion>();
            if (DT != null && DT.Rows.Count > 0)
            {
                foreach (DataRow dr in DT.Rows)
                {
                    Model.CNVP_ProPropertyDescripttion cnvp_propropertydescripttion = new Model.CNVP_ProPropertyDescripttion();
                    cnvp_propropertydescripttion.ID = dr["ID"] is DBNull ? 0 : (int)dr["ID"];
                    cnvp_propropertydescripttion.StandardValue = dr["StandardValue"] is DBNull ? String.Empty : (string)dr["StandardValue"];
                    cnvp_propropertydescripttion.ProTypeRefDescripttionID = dr["ProTypeRefDescripttionID"] is DBNull ? 0 : (int)dr["ProTypeRefDescripttionID"];
                    list.Add(cnvp_propropertydescripttion);
                }
            }
            return list;

        }

        public int DeleteNotIn(int ProductTypeID, string nowid)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("delete from " + Prefix + "ProPropertyDescripttion where [ProductTypeID]=" + ProductTypeID + " and [ProTypeRefDescripttionID] not in (" + nowid + ")");
            return DbHelper.ExecuteNonQuery(sql.ToString());
        }

        public int DeleteNotInID(int ProductID, string nowid)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("delete from " + Prefix + "ProPropertyDescripttion where [ProductID]=" + ProductID + " and [ID] not in (" + nowid + ")");
            return DbHelper.ExecuteNonQuery(sql.ToString());
        }
    }
}

